<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'email', 'password','status','score'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];

    //关联用户详情
    public function userdetail()
    {
        return $this->hasOne('App\Userdetail','id');
    }

    //关联我的订单
      public function orders()
    {
        return $this->hasMany('App\Order','uid');
    }

    //关联我的收藏商品
    public function collect()
    {
        return $this->belongsToMany('App\Goods','goods_user','user_id','goods_id');
    }

    //关联我的优惠券
    public function coupons()
    {
        return $this->belongsTomany('App\Coupon','user_coupons','uid','cid');
    }

    //关联我的购物车
    public function cart()
    {
        return $this->belongsTomany('App\Goods','cart','users_id','goods_id');
    }
}
